package com.ant.storage.controller;


import com.ant.storage.common.ResultVo;
import com.ant.storage.service.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * @author hzd
 * @version 1.0
 * @date 2023/3/16 9:51
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/test")
public class TestController {

    @RequestMapping("/push/{toUserId}")
    public ResponseEntity<String> pushToWeb(String message, @PathVariable String toUserId) throws IOException {
        WebSocketServer.sendInfo(message,toUserId);
        return ResponseEntity.ok("MSG SEND SUCCESS");
    }

    @RequestMapping("/pushes")
    public ResultVo pushToWebes() throws IOException {
        log.info("执行静态定时任务时间: " + LocalDateTime.now());
         String message = "39";
        log.info("播报信息“{}",message);
        WebSocketServer.sendInfo(message,null);
        return ResultVo.success("发送成功");
    }

    @RequestMapping("/test")
    public ResultVo test() throws IOException {
        log.info("执行静态定时任务时间: " + LocalDateTime.now());
        return ResultVo.success("发送成功 回调");
    }
}
